<template>
	<view class="container">
		<view class="header">
			<image src="../../../static/mybg-lei.png" mode="widthFix" class="loginbg"></image>
			<view class="page-title">
				<view class="text-center nav-title">登录</view>
				<view class="text-center logo">
					<image :src="imghost + setting.web_site_logo" mode="widthFix"></image>
				</view>
				<view class="hello">你好，</view>
				<view class="memo">请登录您的手机号及密码</view>
			</view>
			
		</view>
		<view class="tui-form">
			<view class="tui-view-input">
				<tui-list-cell :class="{foc: foc0}" :lineLeft="false" backgroundColor="transparent" :hover="true" padding="8rpx 30rpx">
					<view class="tui-cell-input">
						<tui-icon name="mobile" color="#6d7a87" :size="20"></tui-icon>
						<input
							:adjust-position="false"
							:value="mobile"
							placeholder="请输入手机号"
							placeholder-class="tui-phcolor"
							type="number"
							maxlength="11"
							@input="inputMobile"
							@focus="inputfocus(0)"
							@blur="inputBlur(0)"
						/>
						<view class="tui-icon-close" v-show="mobile" @tap="clearInput(1)"><tui-icon name="close-fill" :size="16" color="#bfbfbf"></tui-icon></view>
					</view>
				</tui-list-cell>
				<tui-list-cell :class="{foc: foc1}" :lineLeft="false" backgroundColor="transparent" :hover="true" padding="8rpx 30rpx">
					<view class="tui-cell-input">
						<tui-icon name="pwd" color="#6d7a87" :size="20"></tui-icon>
						<input
							:adjust-position="false"
							:value="password"
							placeholder="请输入密码"
							:password="true"
							placeholder-class="tui-phcolor"
							type="text"
							maxlength="36"
							@input="inputPwd"
							@focus="inputfocus(1)"
							@blur="inputBlur(1)"
						/>
						<view class="tui-icon-close" v-show="password" @tap="clearInput(2)"><tui-icon name="close-fill" :size="16" color="#bfbfbf"></tui-icon></view>
					</view>
				</tui-list-cell>
			</view>
<!-- 			<view class="tui-cell-text">
				<view class="tui-color-primary" hover-class="tui-opcity" :hover-stay-time="150" @tap="href" data-page="../forgetPwd/forgetPwd"></view>
				<view hover-class="tui-opcity" :hover-stay-time="150">
					没有账号？ 请联系你的推荐人
					 <text class="tui-color-primary"  @tap="href" data-page="../reg/reg">注册</text> -->
				<!-- </view> -->
			<!-- </view> --> 
			<view class="tui-btn-box">
				<tui-button @click="login" type="danger" height="100rpx" :disabledGray="true" :shadow="true" shape="circle">登录</tui-button>
			</view>
				<!-- <view class="tui-cell-text"> -->
					<!-- <view class="tui-color-primary" hover-class="tui-opcity" :hover-stay-time="150"></view> -->
					<!-- <view hover-class="tui-opcity" :hover-stay-time="150"> -->
						<!-- <text class="tui-color-primary"  @tap="href" data-page="/pages/mall/mall">暂不登录</text> -->
					<!-- </view> -->
				<!-- </view> -->
		</view>

	</view>
</template>
<script>
export default {
	computed: {
		disabled: function() {
			let bool = true;
			if (this.mobile && this.password) {
				bool = false;
			}
			return bool;
		}
	},
	data() {
		return {
			imghost:this.tui.imghost,
			setting:[],
			top:0,
			mobile: '',
			password: '',
			popupShow: false,
			foc1:0,
			foc0:0,
		};
	},
	onLoad() {
		let obj = {};
		// #ifdef MP-WEIXIN
		obj = wx.getMenuButtonBoundingClientRect();
		// #endif
		// #ifdef MP-BAIDU
		obj = swan.getMenuButtonBoundingClientRect();
		// #endif
		// #ifdef MP-ALIPAY
		my.hideAddToDesktopMenu();
		// #endif
		uni.getSystemInfo({
			success: (res) => {
				this.width = obj.left || res.windowWidth;
				this.height = obj.top ? (obj.top + obj.height + 8) : (res.statusBarHeight + 44);
				this.top = obj.top ? (obj.top + (obj.height - 32) / 2) : (res.statusBarHeight + 6);
				// this.scrollH = res.windowWidth * 0.6
			}
		})
	},
	onShow() {
		this.tui.get('user/login/chklogin').then(res=>{
			if(res.code===1){
				uni.navigateTo({
					url: '/pages/my/my'
				})
			}
		})
		this.tui.get('user/login/getsetting').then(res=>{
			if(res.code===1){
				this.setting = res.data.setting;
			}else{
				uni.showToast({
				  title: res.data.msg,
				  icon: 'none',
				  duration: 1500
				})
			}
		})
	},
	methods: {
		login:function(e){
			let it =this;
			uni.request({
				url:this.tui.apiUrl('user/login/login'),
				data:{username:this.mobile,password:this.password},
				method:'POST',
				header: {
				  'content-type': 'application/json',
				  'X-Requested-With': 'XMLHttpRequest' 
				},
				success(res){
					if(res.data.code == 1){
						uni.setStorageSync('oauth_token',res.data.data);
						uni.reLaunch({
							url:'../../my/my'
						})
					}else{
						uni.showToast({
						  title: res.data.msg,
						  icon: 'none',
						  duration: 1500
						})
					}
				}
			})
		},
		href:function(e){
			let url = e.currentTarget.dataset.page;
			uni.navigateTo({
				url: url
			})
		},
		back() {
			uni.navigateBack();
		},
		inputMobile: function(e) {
			this.mobile = e.detail.value;
		},
		inputPwd: function(e) {
			this.password = e.detail.value;
		},
		inputfocus:function(idx){
			if(idx == 1){
				this.foc1=1
				this.foc0=0
			}else{
				this.foc0=1
				this.foc1=0
			}
		},
		inputBlur:function(idx){
			if(idx == 1){
				this.foc1=0
			}else{
				this.foc0=0
			}
		},
		clearInput(type) {
			if (type == 1) {
				this.mobile = '';
			} else {
				this.password = '';
			}
		},
		showOtherLogin() {
			//打开后 不再关闭
			this.popupShow = true;
		}
	}
};
</script>

<style lang="scss">
	page{background-color: #FFF;}
	.tui-list-cell::after{
		transition: all 0.5s ease;
	}
	.tui-list-cell.foc::after{
		width: 100%;
		height: 1px;
		border-color: $uni-color-error;
	}
.container {
	.loginbg{width: 100%;}
	.tui-status-bar {
		width: 100%;
		height: var(--status-bar-height);
	}

	.header {
		position: relative;
		.page-title{
			position: absolute;
			left: 0;
			top:0;
			width: 100%;
			color:#FFFFFF;
			padding:0 30upx;
			box-sizing: border-box;
			>view{
				width: 100%;
				text-align: left;
				box-sizing: border-box;
				}
			>.text-center{
				text-align: center;
			}
			.nav-title{
				padding: 40upx;
			}
			.logo{
				padding: 40upx 0 10upx 0;
				image{
					width: 120rpx;
					height: auto;
					margin: 0 auto;
				}
			}
			.hello{
				font-size: 36upx;
			}
			.memo{
				font-size: 32upx;
				padding-top: 20upx;
			}
		}
		
	}
	.tui-page-title {
		width: 100%;
		font-size: 24rpx;
		font-weight: bold;
		color: $uni-text-color;
		line-height: 42rpx;
		padding: 40rpx;
		box-sizing: border-box;
	}

	.tui-form {
		padding-top: 50rpx;

		.tui-view-input {
			width: 100%;
			box-sizing: border-box;
			padding: 0 40rpx;

			.tui-cell-input {
				width: 100%;
				display: flex;
				align-items: center;
				padding-top: 48rpx;
				padding-bottom: $uni-spacing-col-base;

				input {
					flex: 1;
					padding-left: $uni-spacing-row-base;
				}

				.tui-icon-close {
					margin-left: auto;
				}
			}
		}

		.tui-cell-text {
			width: 100%;
			padding: $uni-spacing-col-lg $uni-spacing-row-lg;
			box-sizing: border-box;
			font-size: $uni-font-size-sm;
			color: $uni-text-color-grey;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.tui-color-primary {
				color: $uni-color-primary;
			}
		}

		.tui-btn-box {
			width: 100%;
			padding: 0 $uni-spacing-row-lg;
			box-sizing: border-box;
			margin-top: 80rpx;
		}
	}

	.tui-login-way {
		width: 100%;
		font-size: 26rpx;
		color: $uni-color-primary;
		display: flex;
		justify-content: center;
		position: fixed;
		left: 0;
		bottom: 80rpx;

		view {
			padding: 12rpx 0;
		}
	}

	.tui-auth-login {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		padding-bottom: 80rpx;
		padding-top: 20rpx;

		.tui-icon-platform {
			width: 90rpx;
			height: 90rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			position: relative;
			margin-left: 40rpx;

			&::after {
				content: '';
				position: absolute;
				width: 200%;
				height: 200%;
				transform-origin: 0 0;
				transform: scale(0.5, 0.5) translateZ(0);
				box-sizing: border-box;
				left: 0;
				top: 0;
				border-radius: 180rpx;
				border: 1rpx solid $uni-text-color-placeholder;
			}
		}

		.tui-login-logo {
			width: 60rpx;
			height: 60rpx;
		}
	}
}
</style>
